import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class FileUtil {
    /**
     * @Author: djz
     * @Description: 读取文件数据
     * @DateTime: 2020/8/6 16:08
     * @Params:
     * @Return
     */
    public static List<String> readFileData(String Filename,String coding) {
        List<String> fileData = new ArrayList<String>();
        try {
            InputStreamReader reader = new InputStreamReader(new FileInputStream(new File(Filename.trim())), coding);
            BufferedReader streamReader = new BufferedReader(reader);
            String line = "";
            while ((line = streamReader.readLine()) != null) {
                fileData.add(line);
            }
            reader.close();
            streamReader.close();
        } catch (Exception exception) {
            System.out.println(exception);
        }
        return fileData;
    }

    /**
     * @Author: djz
     * @Description: 写文件信息
     * @DateTime: 2020/8/6 16:08
     * @Params:
     * @Return
     */
    public static void writerFile(String filePath, List<String> data,String coding) {
        try {

            File file = new File(filePath);
            if (file.exists())
                file.delete();
            file.createNewFile();
            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), coding));
            data.forEach(d -> {
                try {
                    bw.write(d);
                    bw.newLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            });
            bw.flush();
            bw.close();
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }
}
